package Colletion;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Code1ArrayList {
    public static void main(String[] args) {
        Collection c1 = new ArrayList();

        c1.add("hello");
        c1.add("world");

        c1.remove("hello");

        System.out.println("remove移除元素"+"\t"+c1);

        c1.add("hello");
        c1.clear();
        System.out.println("clear清除元素"+"\t"+c1);

        c1.add("hello");
        c1.add("world");

        //数组遍历
        Object[] array = c1.toArray();
        for (Object o : array) {
            System.out.println(o+"\t"+o.toString().length());
        }
        //迭代器遍历
        Iterator iterator = c1.iterator();
        while ((iterator.hasNext())!=false){
            Object next = iterator.next();
            System.out.println(next.toString()+"\t"+next.toString().length());
        }

    }
}
